<?php

namespace app\admin\model;

use think\facade\Cache;
use app\common\model\BaseModel;
use think\helper\Str;

class AuthRule extends BaseModel
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    protected static function onAfterWrite($model)
    {
        Cache::delete(config('app.cache_prefix').'__menu__');
    }

    public function getTitleAttr($value, $data)
    {
        return __($value);
    }
    public function getRouteAttr($value, $data)
    {
        if(!empty($data['name'])){
            $value = tp5ControllerToTp6Controller($data['name'],$data['ismenu']);
        }
        return $value;
    }

//    public function setNameAttr($value, $data)
//    {
//        if (empty($data['route'])) {
//            $this->set('route', tp5ControllerToTp6Controller($data['name'],$data['ismenu']));
//        }
//        $this->set('name', $value);
//    }
}
